<form id="editForm" name="editForm" class="layui-form regularEdit"
	action="/product/regular/regularProductEdit.html">
	<input type="hidden" name="id" th:value="${prod}?${prod.id}" />
	<div class="layui-form-item">
		<div class="layui-inline"></div>
	</div>
	<div class="layui-form-item">
		<div class="layui-inline">		
			<label class="layui-form-label">产品名称</label>
			<div class="layui-input-inline">
				<input type="text" id="name" name="name" th:value="${prod}?${prod.name}:''" class="layui-input" lay-verify="required" placeholder="请输入产品名称"/>
			</div>
		</div>
	</div>

	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">产品编号</label>
			<div class="layui-input-inline">
				<input type="text" id="code" name="code" th:value="${prod}?${prod.code}:''" class="layui-input" lay-verify="required|productCode" placeholder="请输入产品编号"/>
			</div>
		</div>
	</div>
	
	<div class="layui-form-item">
		<label class="layui-form-label">投向活期产品</label>
		<div class="layui-input-inline">
			<select name="targetId" lay-filter="targetId">
				<option value="">请选择活期产品</option>
				<option th:each="item:${demandProducts}" th:value="${item.id}"
					th:text="${item.name}"
					th:selected="${prod}ne null and ${prod.targetId==item.id}"></option>
			</select>
		</div>
	</div>
	
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">产品描述</label>
			<div class="layui-input-inline">
				<textarea placeholder="请输入产品描叙" class="layui-textarea" id="description" name="description" th:text="${prod}?${prod.descriptionStr}:''" style="width: 350px;"></textarea>
			</div>
		</div>
	</div>
	
	<div class="layui-form-item">
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit="" lay-filter="addForm">保存</button>
			</div>
		</div>
	</div>
</form>
<style>
	.regularEdit .layui-form-label{width:120px;text-align: right;}
</style>
<script>
	layui.use([ 'jquery', 'form', 'laydate' ], function() {
		var form = layui.form, layer = layui.layer, laydate = layui.laydate;
		form.render();
		//验证
 		form.verify({
 			productCode:function(value,item){  //value：表单的值、item：表单的DOM对象
 				var codeRegex = /^RP{1}[a-zA-Z0-9]+$/;
 				if(!codeRegex.test(value)){     //验证输入的产品编号是否合法
 					return '产品编号必须以RP前缀开头';
 				}
 			},
 			productWeight:function(value,item){   //验证输入的克重
 				if(!/^(0|[1-9][0-9]{0,9})(\.[0-9]{1,4})?$/.test(value)){
 					return '输入的克重不正确（例：999、1888.8934）';
 				}
 			},
 			price:function(value,item){   //验证价格
 				if(!/^(0|[1-9][0-9]{0,9})(\.[0-9]{1,2})?$/.test(value)){
 					return '输入的价格不正确（例：100、99.99）';
 				}
 			},
 			productQuantity:function(value,item){ // 验证库存
 				if(!/^[0-9]*[1-9][0-9]*$/.test(value)){
 					return '库存必须为正整数';
 				}
 			}
 		});
		//监听提交
		form.on('submit(editForm)', function(data) {
			return true;
		});
	});
</script>
